<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>静止向日葵</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #ffffff;
        }
        canvas {
            background-color: #ffffff;
            border-radius: 10px;
            width: 90%; /* 画布宽度适应屏幕 */
            height: auto; /* 高度自动调整，保持画布比例 */
        }
    </style>
</head>
<body>
    <canvas id="sunflowerCanvas"></canvas>
    <script>
        const canvas = document.getElementById("sunflowerCanvas");
        const ctx = canvas.getContext("2d");

        // 动态调整画布大小，适应设备宽度
        function resizeCanvas() {
            canvas.width = window.innerWidth * 0.9; // 设置画布宽度为屏幕宽度的90%
            canvas.height = canvas.width; // 保持画布为正方形
        }

        window.addEventListener('resize', resizeCanvas);
        resizeCanvas(); // 初始化时调整画布大小

        function drawPetal(x, y, angle, color, shadow) {
            ctx.save();
            ctx.translate(x, y);
            ctx.rotate(angle); // 没有摆动，只是旋转花瓣
            ctx.beginPath();
            ctx.moveTo(0, 0);
            ctx.bezierCurveTo(-30, -80, 30, -80, 0, -130);
            ctx.bezierCurveTo(-20, -90, 20, -90, 0, 0);
            ctx.fillStyle = color;
            ctx.shadowColor = shadow;
            ctx.shadowBlur = 10;
            ctx.fill();
            ctx.restore();
        }

        function drawSunflower() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2 + 50;
            const petalCount = 50;
            const petalRadius = 160;

            // 画花瓣
            for (let i = 0; i < petalCount; i++) {
                const angle = (i * (360 / petalCount)) * (Math.PI / 180);
                const x = centerX + Math.cos(angle) * petalRadius;
                const y = centerY + Math.sin(angle) * petalRadius;
                let color = ctx.createRadialGradient(x, y, 5, x, y, 60);
                color.addColorStop(0, "#FFD700");
                color.addColorStop(0.5, "#FFA500");
                color.addColorStop(1, "#FF8C00");
                let shadow = "rgba(0, 0, 0, 0.2)";
                drawPetal(x, y, angle, color, shadow);
            }

            // 画花心
            let gradient = ctx.createRadialGradient(centerX, centerY, 15, centerX, centerY, 100);
            gradient.addColorStop(0, "#3E2723");
            gradient.addColorStop(0.5, "#5A3A22");
            gradient.addColorStop(1, "#8B4513");
            ctx.fillStyle = gradient;
            ctx.beginPath();
            ctx.arc(centerX, centerY, 100, 0, Math.PI * 2);
            ctx.fill();

            // 画茎
            let stemGradient = ctx.createLinearGradient(centerX, centerY + 80, centerX, canvas.height);
            stemGradient.addColorStop(0, "#2E8B57");
            stemGradient.addColorStop(1, "#1B5E20");
            ctx.beginPath();
            ctx.moveTo(centerX, centerY + 80);
            ctx.quadraticCurveTo(centerX - 50, centerY + 400, centerX, canvas.height); // 茎部不摆动
            ctx.lineWidth = 30;
            ctx.strokeStyle = stemGradient;
            ctx.stroke();
            ctx.closePath();

            // 画叶子
            function drawLeaf(cx, cy, angle) {
                ctx.save();
                ctx.translate(cx, cy);
                ctx.rotate(angle); // 叶子保持静止
                ctx.beginPath();
                ctx.moveTo(0, 0);
                ctx.bezierCurveTo(-70, -40, -70, 40, 0, 80);
                ctx.bezierCurveTo(70, 40, 70, -40, 0, 0);
                let leafGradient = ctx.createLinearGradient(-70, 0, 70, 80);
                leafGradient.addColorStop(0, "#228B22");
                leafGradient.addColorStop(1, "#145A32");
                ctx.fillStyle = leafGradient;
                ctx.fill();
                ctx.restore();
            }
            drawLeaf(centerX - 70, centerY + 200, -0.8);
            drawLeaf(centerX + 70, centerY + 250, 0.8);
        }

        function animate() {
            drawSunflower();
            requestAnimationFrame(animate);
        }

        animate();
    </script>
</body>
</html>
